"""Branch Coverage Manager"""

from ios_cov_manager.lib.string_util import get_replaced_branch_name


class BranchCoverage:
    """Branch coverage information

    The coverage is based on the branch a.k.a `branch coverage`
    The coverage is so called `branch coverage`
    There are two levels of `branch coverage`:

    1. Version level `branch coverage`
    2. Build level `branch coverage`

    The relationship between the branch and the version is one-to-one correspondence
    """

    def __init__(
        self,
        build_machine_repo_path: str,
        ios_repo_git_url: str,
        branch_name: str,
        version: str,
        build_number: str = None,
        commit_id: str = None,
    ) -> None:
        self.build_machine_repo_path = build_machine_repo_path
        self.ios_repo_git_url = ios_repo_git_url
        # Check if the iOS repository URL ends with .git and get the repository name
        if not self.ios_repo_git_url.endswith(".git"):
            raise ValueError("ios_repo_git_url must end with .git")
        self.ios_repo_name = self.ios_repo_git_url.split("/")[-1].replace(".git", "")
        self.branch_name = branch_name
        self.replaced_branch_name = get_replaced_branch_name(branch_name=branch_name)
        self.version = version
        self.build_number = build_number
        self.commit_id = commit_id
